package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class KeyboardUserInput implements UserInput {

    private static BufferedReader keyboardInput = new BufferedReader(new InputStreamReader(System.in));

    public int acceptValidIntRangeInput(int sRange, int eRange, String msg) {
        int input;
        try{
            do{
                System.out.print(msg);
                input = Integer.parseInt(keyboardInput.readLine());
            }while(input<sRange || input>eRange);
        }
        catch (IOException e){
            System.out.println("IOException");
            input =  0;
        }
        catch (NumberFormatException e){
            System.out.println("Invalid Number");
            input = 0;
        }
        catch(Exception e){
            System.out.println("UserInput Error");
            input = 0;
        }


        return input;
    }

    public String getInput(){
        String output = "";
        try{
            output = keyboardInput.readLine();
        }
        catch(IOException e){
            System.out.println("IOException");
        }
        return output;
    }
}
